package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.CompanyDao;
import com.cn.wanxi.dao.impl.CompanyImpl;
import com.cn.wanxi.dto.CompanyDto;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.ICompanyService;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 服务逻辑层
 */
public class CompanyServiceImpl implements ICompanyService {

    @Override
    public int add(CompanyDto companyDto) {
        CompanyModel companyModel = new CompanyModel();
        companyModel.setLogo(companyDto.getLogo());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss sss");
        System.out.println(new Date().toString());
        companyModel.setCreateTime(simpleDateFormat.format(new Date()));
        companyModel.setName(companyDto.getName());
        companyModel.setAd(companyDto.getAd());
        companyModel.setPhone(companyDto.getPhone());
        companyModel.setCompanyIntroduce(companyDto.getContent());
//        调用数据接口层
        CompanyDao companyDao = new CompanyImpl();


        return companyDao.add(companyModel);
    }

    @Override
    public CompanyModel getCompanyModel() {
        CompanyDao companyDao = new CompanyImpl();
        return companyDao.getCompanyModel();
    }

    @Override
    public ResultModel findAll() {
        CompanyDao companyDao = new CompanyImpl();
        ResultModel resultModel=new ResultModel();
        resultModel.setObject(companyDao.findAll());
        return resultModel;
    }

    @Override
    public ResultModel findById(int id) {
        ResultModel resultModel=new ResultModel();
        CompanyDao companyDao = new CompanyImpl();
        resultModel.setObject(companyDao.findById(id));
        return resultModel;
    }
}
